<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/Admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="cname" class="layui-form-label">
                        ID
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="id" name="id" required="" lay-verify="required"
                        autocomplete="off"  value="<?php echo $rule['id'] ?>" disabled="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        规则
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="cnnameame" required="" lay-verify="required"
                        autocomplete="off"  value="<?php echo $rule['name'] ?>"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="title" class="layui-form-label">
                        规则名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="title" name="title" required="" lay-verify="required"
                        autocomplete="off"  value="<?php echo $rule['title'] ?>"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属分类</label>
                    <div class="layui-input-inline" >
                        <select name="cid">
                            <?php foreach ($cate as $v) { ?>
                                <option value="<?php echo $v['id'] ?>" <?php if($v['id']==$rule['cid']) echo "selected"; ?> ><?php echo $v['cname'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <input type="hidden" value="<?php echo $rule['id'] ?>" name='id'>
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="save" lay-submit="">
                        保存
                    </button>
                </div>
            </form>
        </div>
        <script src="__PUBLIC__/Admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="__PUBLIC__/Admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
            

              //监听提交
              form.on('submit(save)', function(data){
                console.log(data);
                $.ajax({
                    url: '{:U('admin/auth/rule_update')}',
                    type: 'POST',
                    dataType: 'json',
                    data:data.field,
                })
                .done(function(respon) {
                    if(respon.error==0){

                        //发异步，把数据提交给php
                        layer.alert(respon.info, {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.location.reload();
                        });

                    }else{
                        layer.msg(respon.info, {icon: 1});
                    }
                })
                
                
                return false;
              });
              
              
            });
        </script>
    </body>

</html>